{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.pow: tensor([ 2.7183,  7.3891, 20.0855])\n",
      "mcLaughlin_ex: tensor([ 2.7183,  7.3890, 20.0797])\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "import math\n",
    "#Pytorch计算f(x)=e^x的10阶麦克劳林展开的近似值。\n",
    "x = torch.Tensor([1,2,3])\n",
    "print(\"torch.pow:\",torch.pow(math.e,x))\n",
    "\n",
    "#10阶麦克劳林公式近似计算e^x次方\n",
    "def mcLaughlin_ex(x):\n",
    "    _sum = 1\n",
    "    for i in range(1,11):\n",
    "        _sum = _sum + x**i/math.factorial(i)\n",
    "    return _sum\n",
    "\n",
    "print(\"mcLaughlin_ex:\",mcLaughlin_ex(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
